﻿using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using Gola.VN.Scb.Web.Presentation.Models;

namespace Gola.VN.Scb.Web.Presentation
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : HttpApplication
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            #region using for customer register

            routes.MapRoute(
                "CustomerRegister",
                "tai-khoan-gian-hang/dang-ki",
                new {controller = "Customer", action = "Register"}
                );

            #endregion

            #region using for customer logon

            routes.MapRoute(
                "CustomerLogOn",
                "tai-khoan-gian-hang/dang-nhap",
                new {controller = "Customer", action = "LogOn"}
                );

            #endregion

            #region using for customer logout

            routes.MapRoute(
                "CustomerLogOut",
                "tai-khoan-gian-hang/dang-xuat",
                new {controller = "Customer", action = "LogOff"}
                );

            #endregion

            #region using for customer change password

            routes.MapRoute(
                "CustomerChangePassword",
                "tai-khoan-gian-hang/thay-doi-mat-khau",
                new {controller = "Customer", action = "ChangePassword"}
                );

            #endregion

            #region using for customer change store infomation

            routes.MapRoute(
                "CustomChangeInformation",
                "tai-khoan-gian-hang/thay-doi-thong-tin-gian-hang",
                new {controller = "Customer", action = "CustomerChangeInformation"}
                );

            #endregion

            #region using for customer add product

            routes.MapRoute(
                "CustomerAddProduct", // Route name
                "cap-nhat-gian-hang/them-san-pham-moi", // URL with parameters
                new {controller = "Customer", action = "AddProduct"} // Parameter defaults
                );

            #endregion

            #region using for customer store

            routes.MapRoute(
                "CustomerStore", // Route name
                "gian-hang/{userName}/{categoryName}", // URL with parameters
                new
                    {
                        controller = "Customer",
                        action = "CustomerStore",
                        userName = UrlParameter.Optional,
                        categoryName = UrlParameter.Optional
                    } // Parameter defaults
                );

            #endregion

            routes.MapRoute(
                "pagination",
                "san-pham/{id}/{keyword}",
                new
                    {
                        controller = "Product",
                        action = "DisplayProducts",
                        id = UrlParameter.Optional,
                        keyword = UrlParameter.Optional
                    }
                );

            #region using for display product detail and all products with same title

            routes.MapRoute(
                "deltailsProduct",
                "chi-tiet-san-pham-so-sanh/{id}/{keyword}",
                new
                    {
                        controller = "Product",
                        action = "ProductDetail",
                        id = UrlParameter.Optional,
                        keyword = UrlParameter.Optional
                    }
                );

            #endregion

            #region using for display product detail in provider site

            routes.MapRoute(
                "gotoWebsite",
                "chi-tiet-san-pham/{id}/{provider}/{keyword}",
                new
                    {
                        controller = "Product",
                        action = "GoToWebsite",
                        id = UrlParameter.Optional,
                        provider = UrlParameter.Optional,
                        keyword = UrlParameter.Optional
                    }
                );

            #endregion

            routes.MapRoute(
                "category",
                "danh-muc/{id}/{keyword}",
                new
                    {
                        controller = "Category",
                        action = "Display",
                        id = UrlParameter.Optional,
                        keyword = UrlParameter.Optional
                    }
                );

            routes.MapRoute(
                "displayProducts",
                "san-pham/{id}/q/{*queryvalues}",
                new {controller = "Product", action = "DisplayProducts", id = UrlParameter.Optional}
                );

            routes.MapRoute(
                "detailProducts",
                "{category}/{id}/q/{*queryvalues}",
                new {controller = "Product", action = "ProductDetail", id = UrlParameter.Optional}
                );

            routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new {controller = "Home", action = "Index", id = UrlParameter.Optional} // Parameter defaults
                );
        }

        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            RegisterRoutes(RouteTable.Routes);
            //regis other thread to load data from db
            DataRespository.Initialize();
        }
    }
}